{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Import libraries\n",
    "import pandas as pd\n",
    "import numpy as np"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Create Data\n",
    "To be able to visualize data, we first need to be able to get and manipulate data. In this section, we are going to create our own data.\n",
    "\n",
    "The data is the start of a payment table for a car loan of 34690 dollars with a 7.02 interest rate over 60 months."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Approach 1 List\n",
    "carLoans = [[1, 34689.96, 687.23, 202.93, 484.3, 34205.66, 60, 0.0702,'Toyota Sienna'],\n",
    "           [2, 34205.66, 687.23, 200.1, 487.13, 33718.53, 60, 0.0702,'Toyota Sienna'],\n",
    "           [3, 33718.53, 687.23, 197.25, 489.98, 33228.55, 60, 0.0702,'Toyota Sienna'],\n",
    "           [4, 33228.55, 687.23, 194.38, 492.85, 32735.7, 60, 0.0702,'Toyota Sienna'],\n",
    "           [5, 32735.7, 687.23, 191.5, 495.73, 32239.97, 60, 0.0702,'Toyota Sienna']]\n",
    "\n",
    "colNames = ['Month',\n",
    "            'Starting Balance',\n",
    "            'Repayment',\n",
    "            'Interest Paid',\n",
    "            'Principal Paid',\n",
    "            'New Balance',\n",
    "            'term',\n",
    "            'interest_rate',\n",
    "            'car_type']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "df = pd.DataFrame(data = carLoans, columns=colNames)\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Approach 2 NumPy Array\n",
    "carLoans = np.array([\n",
    "                  [1, 34689.96, 687.23, 202.93, 484.3, 34205.66, 60, 0.0702,'Toyota Sienna'],\n",
    "                  [2, 34205.66, 687.23, 200.1, 487.13, 33718.53, 60, 0.0702,'Toyota Sienna'],\n",
    "                  [3, 33718.53, 687.23, 197.25, 489.98, 33228.55, 60, 0.0702,'Toyota Sienna'],\n",
    "                  [4, 33228.55, 687.23, 194.38, 492.85, 32735.7, 60, 0.0702,'Toyota Sienna'],\n",
    "                  [5, 32735.7, 687.23, 191.5, 495.73, 32239.97, 60, 0.0702,'Toyota Sienna']\n",
    "                 ])\n",
    "   \n",
    "colNames = ['Month',\n",
    "            'Starting Balance',\n",
    "            'Repayment',\n",
    "            'Interest Paid',\n",
    "            'Principal Paid',\n",
    "            'New Balance',\n",
    "            'term',\n",
    "            'interest_rate',\n",
    "            'car_type']\n",
    "\n",
    "df = pd.DataFrame(data = carLoans, columns=colNames)\n",
    "df "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Approach 3 Python Dictionary\n",
    "carLoans = {'Month': {0: 1, 1: 2, 2: 3, 3: 4, 4: 5},\n",
    "             'Starting Balance': {0: 34689.96,1: 34205.66,2: 33718.53,3: 33228.55,4: 32735.7},\n",
    "             'Repayment': {0: 687.23, 1: 687.23, 2: 687.23, 3: 687.23, 4: 687.23},\n",
    "             'Interest Paid': {0: 202.93, 1: 200.1, 2: 197.25, 3: 194.38, 4: 191.5},\n",
    "             'Principal Paid': {0: 484.3, 1: 487.13, 2: 489.98, 3: 492.85, 4: 495.73},\n",
    "             'New Balance': {0: 34205.66,1: 33718.53,2: 33228.55,3: 32735.7,4: 32239.97},\n",
    "             'term': {0: 60, 1: 60, 2: 60, 3: 60, 4: 60},\n",
    "             'interest_rate': {0: 0.0702, 1: 0.0702, 2: 0.0702, 3: 0.0702, 4: 0.0702},\n",
    "             'car_type': {0: 'Toyota Sienna',1: 'Toyota Sienna',2: 'Toyota Sienna',3: 'Toyota Sienna',4: 'Toyota Sienna'}}\n",
    "\n",
    "df = pd.DataFrame(data = carLoans)\n",
    "df"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Limitation of this Approach\n",
    "If you have a larger dataset (like the entire payment table), it doesnt make sense to manually put data into a dataframe. "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# this is painfully slow to type\n",
    "carLoans = [\n",
    "            [1, 34689.96, 687.23, 202.93, 484.3, 34205.66, 60, 0.0702, 'Toyota Sienna'],\n",
    "            [2, 34205.66, 687.23, 200.1, 487.13, 33718.53, 60, 0.0702, 'Toyota Sienna'],\n",
    "            [3, 33718.53, 687.23, 197.25, 489.98, 33228.55, 60, 0.0702, 'Toyota Sienna'],\n",
    "            [4, 33228.55, 687.23, 194.38, 492.85, 32735.7, 60, 0.0702, 'Toyota Sienna'],\n",
    "            [5, 32735.7, 687.23, 191.5, 495.73, 32239.97, 60, 0.0702, 'Toyota Sienna'],\n",
    "            [6, 32239.97, 687.23, 188.6, 498.63, 31741.34, 60, 0.0702, 'Toyota Sienna'],\n",
    "            [7, 31741.34, 687.23, 185.68, 501.55, 31239.79, 60, 0.0702, 'Toyota Sienna'],\n",
    "            [8, 31239.79, 687.23, 182.75, 504.48, 30735.31, 60, 0.0702, 'Toyota Sienna'],\n",
    "            [9, 30735.31, 687.23, 179.8, 507.43, 30227.88, 60, 0.0702, 'Toyota Sienna'],\n",
    "            [10, 30227.88, 687.23, 176.83, 510.4, 29717.48, 60, 0.0702, 'Toyota Sienna'],\n",
    "            [11, 29717.48, 687.23, 173.84, 513.39, 29204.09, 60, 0.0702, 'Toyota Sienna'],\n",
    "            [12, 29204.09, 687.23, 170.84, 516.39, 28687.7, 60, 0.0702, 'Toyota Sienna'],\n",
    "            [13, 28687.7, 687.23, 167.82, 519.41, 28168.29, 60, 0.0702, 'Toyota Sienna'],\n",
    "            [14, 28168.29, 687.23, 164.78, 522.45, 27645.84, 60, 0.0702, 'Toyota Sienna'],\n",
    "            [15, 27645.84, 687.23, 161.72, 525.51, 27120.33, 60, 0.0702, 'Toyota Sienna'],\n",
    "            [16, 27120.33, 687.23, 158.65, 528.58, 26591.75, 60, 0.0702, 'Toyota Sienna'],\n",
    "            [17, 26591.75, 687.23, 155.56, 531.67, 26060.08, 60, 0.0702, 'Toyota Sienna'],\n",
    "            [18, 26060.08, 687.23, 152.45, 534.78, 25525.3, 60, 0.0702, 'Toyota Sienna'],\n",
    "            [19, 25525.3, 687.23, 149.32, 537.91, 24987.39, 60, 0.0702, 'Toyota Sienna'],\n",
    "            [20, 24987.39, 687.23, 146.17, 541.06, 24446.33, 60, 0.0702, 'Toyota Sienna'],\n",
    "            [21, 24446.33, 687.23, 143.01, 544.22, 23902.11, 60, 0.0702, 'Toyota Sienna'],\n",
    "            [22, 23902.11, 687.23, 139.82, 547.41, 23354.7, 60, 0.0702, 'Toyota Sienna'],\n",
    "            [23, 23354.7, 687.23, 136.62, 550.61, 22804.09, 60, 0.0702, 'Toyota Sienna'],\n",
    "            [24, 22804.09, 687.23, 133.4, 553.83, 22250.26, 60, 0.0702, 'Toyota Sienna'],\n",
    "            [25, 22250.26, 687.23, 130.16, 557.07, 21693.19, 60, 0.0702, 'Toyota Sienna'],\n",
    "            [26, 21693.19, 687.23, 126.9, 560.33, 21132.86, 60, 0.0702, 'Toyota Sienna'],\n",
    "            [27, 21132.86, 687.23, 123.62, 563.61, 20569.25, 60, 0.0702, 'Toyota Sienna'],\n",
    "            [28, 20569.25, 687.23, 120.33, 566.9, 20002.35, 60, 0.0702, 'Toyota Sienna'],\n",
    "            [29, 20002.35, 687.23, 117.01, 570.22, 19432.13, 60, 0.0702, 'Toyota Sienna'],\n",
    "            [30, 19432.13, 687.23, 113.67, 573.56, 18858.57, 60, 0.0702, 'Toyota Sienna'],\n",
    "            [31, 18858.57, 687.23, 110.32, 576.91, 18281.66, 60, 0.0702, 'Toyota Sienna'],\n",
    "            [32, 18281.66, 687.23, 106.94, 580.29, 17701.37, 60, 0.0702, 'Toyota Sienna'],\n",
    "            [33, 17701.37, 687.23, 103.55, 583.68, 17117.69, 60, 0.0702, 'Toyota Sienna'],\n",
    "            [34, 17117.69, 687.23, 100.13, 587.1, 16530.59, 60, 0.0702, 'Toyota Sienna'],\n",
    "            [35, 16530.59, 687.23, 96.7, 590.53, 15940.06, 60, 0.0702, 'Toyota Sienna'],\n",
    "            [36, 15940.06, 687.23, 93.24, 593.99, 15346.07, 60, 0.0702, 'Toyota Sienna'],\n",
    "            [37, 15346.07, 687.23, 89.77, 597.46, 14748.61, 60, 0.0702, 'Toyota Sienna'],\n",
    "            [38, 14748.61, 687.23, 86.27, 600.96, 14147.65, 60, 0.0702, 'Toyota Sienna'],\n",
    "            [39, 14147.65, 687.23, 82.76, 604.47, 13543.18, 60, 0.0702, 'Toyota Sienna'],\n",
    "            [40, 13543.18, 687.23, 79.22, 608.01, 12935.17, 60, 0.0702, 'Toyota Sienna'],\n",
    "            [41, 12935.17, 687.23, 75.67, 611.56, 12323.61, 60, 0.0702, 'Toyota Sienna'],\n",
    "            [42, 12323.61, 687.23, 72.09, 615.14, 11708.47, 60, 0.0702, 'Toyota Sienna'],\n",
    "            [43, 11708.47, 687.23, 68.49, 618.74, 11089.73, 60, 0.0702, 'Toyota Sienna'],\n",
    "            [44, 11089.73, 687.23, 64.87, 622.36, 10467.37, 60, 0.0702, 'Toyota Sienna'],\n",
    "            [45, 10467.37, 687.23, 61.23, 626.0, 9841.37, 60, 0.0702, 'Toyota Sienna'],\n",
    "            [46, 9841.37, 687.23, 57.57, 629.66, 9211.71, 60, 0.0702, 'Toyota Sienna'],\n",
    "            [47, 9211.71, 687.23, 53.88, 633.35, 8578.36, 60, 0.0702, 'Toyota Sienna'],\n",
    "            [48, 8578.36, 687.23, 50.18, 637.05, 7941.31, 60, 0.0702, 'Toyota Sienna'],\n",
    "            [49, 7941.31, 687.23, 46.45, 640.78, 7300.53, 60, 0.0702, 'Toyota Sienna'],\n",
    "            [50, 7300.53, 687.23, 42.7, 644.53, 6656.0, 60, 0.0702, 'Toyota Sienna'],\n",
    "            [51, 6656.0, 687.23, 38.93, 648.3, 6007.7, 60, 0.0702, 'Toyota Sienna'],\n",
    "            [52, 6007.7, 687.23, 35.14, 652.09, 5355.61, 60, 0.0702, 'Toyota Sienna'],\n",
    "            [53, 5355.61, 687.23, 31.33, 655.9, 4699.71, 60, 0.0702, 'Toyota Sienna'],\n",
    "            [54, 4699.71, 687.23, 27.49, 659.74, 4039.97, 60, 0.0702, 'Toyota Sienna'],\n",
    "            [55, 4039.97, 687.23, 23.63, 663.6, 3376.37, 60, 0.0702, 'Toyota Sienna'],\n",
    "            [56, 3376.37, 687.23, 19.75, 667.48, 2708.89, 60, 0.0702, 'Toyota Sienna'],\n",
    "            [57, 2708.89, 687.23, 15.84, 671.39, 2037.5, 60, 0.0702, 'Toyota Sienna'],\n",
    "            [58, 2037.5, 687.23, 11.91, 675.32, 1362.18, 60, 0.0702, 'Toyota Sienna'],\n",
    "            [59, 1362.18, 687.23, 7.96, 679.27, 682.91, 60, 0.0702, 'Toyota Sienna'],\n",
    "            [60, 682.91, 687.23, 3.99, 683.24, -0.33, 60, 0.0702, 'Toyota Sienna']\n",
    "            ]\n",
    "\n",
    "colNames = ['Month',\n",
    "            'Starting Balance',\n",
    "            'Repayment',\n",
    "            'Interest Paid',\n",
    "            'Principal Paid',\n",
    "            'New Balance',\n",
    "            'term',\n",
    "            'interest_rate',\n",
    "            'car_type']\n",
    "\n",
    "df = pd.DataFrame(data = carLoans, columns=colNames)\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "help(pd.DataFrame)"
   ]
  }
 ],
 "metadata": {
  "anaconda-cloud": {},
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}
